Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON decode crash in PictureViewerFragment #3627

Merged

Conversation

pascalwei
Copy link
Contributor

The arguments for sorting are provided as a String, not as JSON. Attemping to decode the String crashes the app. Fix it by using the SDK provided methods to convert to an enum instead.

Trigger crash:

  1. Open an image from an image library

Stack trace:

E  ACRA caught a JsonDecodingException for org.jellyfin.androidtv.debug
                                                                                                    kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 0: Expected quotation mark '"', but had 'S' instead at path: $
                                                                                                    JSON input: SortName
                                                                                                    	at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)
                                                                                                    	at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:598)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$default(AbstractJsonLexer.kt:596)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:233)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json$default(AbstractJsonLexer.kt:228)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken(AbstractJsonLexer.kt:225)
                                                                                                    	at kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken(StringJsonLexer.kt:74)
                                                                                                    	at kotlinx.serialization.json.internal.StringJsonLexer.consumeKeyString(StringJsonLexer.kt:86)
                                                                                                    	at kotlinx.serialization.json.internal.AbstractJsonLexer.consumeString(AbstractJsonLexer.kt:383)
                                                                                                    	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeString(StreamingJsonDecoder.kt:339)
                                                                                                    	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeEnum(StreamingJsonDecoder.kt:352)
                                                                                                    	at kotlinx.serialization.internal.EnumSerializer.deserialize(Enums.kt:139)
                                                                                                    	at kotlinx.serialization.internal.EnumSerializer.deserialize(Enums.kt:105)
                                                                                                    	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:69)
                                                                                                    	at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
                                                                                                    	at org.jellyfin.androidtv.ui.picture.PictureViewerFragment$onCreate$1.invokeSuspend(PictureViewerFragment.kt:229)
                                                                                                    	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                    	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:363)
                                                                                                    	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:26)
                                                                                                    	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:21)
                                                                                                    	at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:88)
                                                                                                    	at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:123)
                                                                                                    	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:52)
                                                                                                    	at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
                                                                                                    	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:43)
                                                                                                    	at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
                                                                                                    	at org.jellyfin.androidtv.ui.picture.PictureViewerFragment.onCreate(PictureViewerFragment.kt:60)
                                                                                                    	at androidx.fragment.app.Fragment.performCreate(Fragment.java:3095)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:516)
                                                                                                    	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:274)
                                                                                                    	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2103)
                                                                                                    	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1998)
                                                                                                    	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1941)
                                                                                                    	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:661)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:958)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                    	at android.os.Looper.loop(Looper.java:294)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

The arguments are provided as a String, not as JSON. Use the SDK provided methods to convert to an enum instead.
Copy link
Member

@nielsvanvelzen nielsvanvelzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find

@nielsvanvelzen nielsvanvelzen added this to the v0.17.0 milestone May 31, 2024
@nielsvanvelzen nielsvanvelzen added bug Something isn't working crash Bug causing app crashes labels May 31, 2024
@nielsvanvelzen nielsvanvelzen merged commit f31a809 into jellyfin:master May 31, 2024
5 checks passed
@pascalwei pascalwei deleted the bugfix/picture-viewer-fragment-json branch June 9, 2024 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash Bug causing app crashes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants